home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-07-21 | 1.7 KB | 44 lines | [TEXT/EDIT] |
- ( FloatingPoint ) hex
- ( a simple implementation of sane stuff )
-
- 2variable FPIN ( integer input variable )
- : FLOAT ( compile: -- ) ( run: -- addr ) variable 8 allot ;
- : 4PACK ( -- ) ,$ A9EB ; macro ( compile a _Pack4 trap )
- : FOP2 ( source dest opword -- ) rot a>r swap a>r >r 4pack ;
- : F! ( d float -- ) >r here 2! r> here a>r a>r 280E >r 4pack ;
- : F@ ( float -- d ) a>r here a>r 2810 >r 4pack here 2@ ;
- : F+ ( float1 float2 -- ) 0 fop2 ; ( f1 + f2 -> f2 )
- : F* ( float1 float2 -- ) 4 fop2 ; ( f1 * f2 -> f2 )
- : F- ( float1 float2 -- ) 2 fop2 ; ( f2 - f1 -> f2 )
- : F/ ( float1 float2 -- ) 6 fop2 ; ( f2 / f1 -> f2 )
- : FROOT ( float -- ) a>r 12 >r 4pack ; ( √f -> f )
- : F^2 ( float -- ) dup f* ; ( f^2 -> f )
-
- decimal
- 2variable FORM 10 0 form 2! ( decform record )
- : PLACES ( -- n ) form 2+ @ 1- ; ( number of decimal places )
- : F. ( float -- ) ( print float in base 10 scientific notation )
- here 25 0 fill ( prepare conversion area )
- form a>r a>r here a>r 11 >r 4pack ( convert )
- here @ IF 45 emit THEN ( print - if negative )
- here 5 + 1 type ( print first digit )
- 8 emit 46 emit here 6 + places type ( print decimal part )
- 69 emit here 2+ @ places + . ; ( print exponent )
-
- ( floating point example: use pythagorean theorem )
- float S1 ( create a floating point number for side 1 )
- float S2 ( create another float for side 2 )
-
- : PYTH ( side1 side2 -- ) ( print hypotenuse two ways )
- s>d s2 f! s>d s1 f! ( setup s1, s2 floats )
- s1 f^2 s2 f^2 s1 s2 f+ s2 froot ( calc: √[s1^2+s2^2] )
- s2 f. cr ( print it in scientific notation )
- s2 f@ d. ; ( print nearest integer )
-
- page
- ( Try it out! )
-
- 300 400 pyth ( should be 500 )
-
- 286 549 pyth ( should be 619.029078477 by my HP-48 calc )
-